package com.smart.util;

import java.io.File;
import java.io.FileInputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Properties;

public class DBUtil {
	
	private static String user;
	private static String url;
	private static String pass;
	private static String driver;
    private static Properties props=null;
    private static Connection conn=null;
    static
    {
		try {
			initParam();
			Class.forName(driver);
			System.out.println("url:"+url+","+"user:"+user+","+"pass:"+pass);
			conn=DriverManager.getConnection(url,user,pass);
			if(conn==null) System.out.println("conn error");
		} catch (Exception e) {
			e.printStackTrace();
		}
		
    }
    public static Connection getConnection()
    {
    	return conn;
    }
    public  static void initParam() throws Exception
    {
    	//File f=new File("ini/mysql.ini");
    	props=new Properties();
    	//props.load(new FileInputStream(f));
    	//user=props.getProperty("user");
    	user="root";
    	//driver=props.getProperty("driver");
    	driver="com.mysql.jdbc.Driver";
    	//url=props.getProperty("url");
    	url="jdbc:mysql://localhost:3306/smart?characterEncoding=utf-8";
        //pass=props.getProperty("pass");
     	pass="19930923";
    }
}